<template>
  <div class="body-box">
    <el-form
      label-width="80px"
      label-position="left"
      size="small"
      style="width:500px;"
      :model="form"
      :rules="rules"
      ref="form"
    >
      <el-form-item label="原密码" prop="old_pwd">
        <el-input placeholder="请输入原密码" type="password" v-model="form.old_pwd"></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="new_pwd">
        <el-input placeholder="请输入新密码" type="password" v-model="form.new_pwd"></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="re_pwd">
        <el-input placeholder="请输入确认密码" type="password" v-model="form.re_pwd"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="com-btn" @click="submit()">提交修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        old_pwd: "",
        new_pwd: "",
        re_pwd: ""
      },
      rules: {
        old_pwd: [{ required: true, message: "请输入原密码", trigger: "blur" }],
        new_pwd: [{ required: true, message: "请输入新密码", trigger: "blur" }],
        re_pwd: [{ required: true, message: "请输入确认密码", trigger: "blur" }]
      }
    };
  },
  methods: {
    submit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.new_pwd != this.form.re_pwd)
            return this.toast(0, "两次输入的密码不一致");
          this.ajaxs("club/updatePwd", {
            data: this.form,
            success: res => {
              this.toast(res.code, res.msg);
              if (res.code) {
                this.$alert("密码修改成功，请重新登陆", "温馨提示", {
                  confirmButtonText: "确定",
                  callback: action => {
                    location.reload();
                  }
                });
              }
            }
          });
        }
      });
    }
  }
};
</script>

<style>
</style>